import { isArray } from "lodash-es";

export const getUri = (uri: string, req: { [_: string]: any }) => {
  const urlSearchParams = new URLSearchParams();
  Object.keys(req).forEach((key) => {
    if (isArray(req[key])) {
      req[key].length && urlSearchParams.set(key, req[key].join(","));
    } else if (typeof req[key] === "object") {
      for (const k in req[key]) {
        urlSearchParams.set(k, req[key]);
      }
    } else if (req[key] !== undefined) {
      urlSearchParams.set(key, req[key]);
    }
  });
  return `${uri}?${urlSearchParams.toString()}`;
};
